home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
turbovis
/
dlgds411.zip
/
READSCPT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1994-01-02
|
17KB
|
688 lines
{$A-,B-,E+,F-,G-,I+,N-,O-,P-,Q-,R-,S-,T-,V-,X+}
Unit ReadScpt;
Interface
uses Dos, Objects;
const
MaxParam = 6; {number of extra parameters}
Type
{various types of controls which may be found in script file. -1 indicates
end}
RecType = (Dlg, Button, SText, CText, InputL, Labl, Histry, ILong, CheckB,
RadioB, MultiCB, ListB, Memo, ScrollB);
{various types of validators for TInputLine}
ValType = (Picture, Range, Filter, StringLookup);
BlockType = record {all controls have this standard data block}
BaseObj, {like TInputLine}
Obj : PString; {like PInputLine or PMyInputLine}
X1, Y1, X2, Y2, {the TRect}
DefOptns, Optns, {default and actual options for control}
DefEvMsk, EvMsk, {default and actual eventmask for control}
HCtx, {HelpCtx value}
Grow : integer; {GrowMode value}
Param : array[1..MaxParam] of PString; {possible the extra parameters}
HelpCtxSym, {like hcNoContext}
FieldName, {field name you chose for data record}
VarName : PString; {variable name you chose or 'Control'}
end;
ScriptRec = record {the variant record for the various controls}
MainBlock : BlockType; {the fixed part for all controls}
case Kind: RecType of
Dlg: (Palette, WinFlags : word; {the dialog itself}
DlgFuncName, {like MakeDialog}
KeyString, {ID string for resource}
Title : PString;); {dialog title}
Button:
(CommandName, {like cmOK}
ButtonText : PString; {like O~k~}
CommandValue, {word value for Command}
Flags : word;); {flags}
SText, CText: {static and colored text}
(Attrib : word;
Text : PString;);
InputL:
(StringLeng : word; {AMaxLen parameter}
ValPtrName : PString; {like PPXPictureString}
case ValKind : ValType of {ValKind = -1 if no validator}
Picture:
(AutoFill : Byte;
PictureString : PString;);
Range:
(LowLim, UpLim : LongInt;
Transfer : word;); {non-zero if voTransfer bit set}
StringLookUp:
(List : PString;);
Filter:
(CharSet : PString; {like "['a'..'z', '0'..'9']" }
{following represents the actual character set}
ActualCharSet : array[0..7] of LongInt;
);
);
ILong:
(LongLabelText : PString; {text of the label--not used in Pascal}
LongStrLeng : word; {AMaxlen parameter}
LLim, ULim : LongInt;
ILOptions : word;);
LabL: (LabelText,
LinkName : PString;); {variable name of control to which
label is linked, often just 'Control'}
Histry:
(HistoryID : word;
HistoryLink : PString;); {variable name of control to which
label is linked, often just 'Control'}
CheckB, RadioB, MultiCB:
(Items : word; {number of labels}
Mask : LongInt;
LabelColl : PStringCollection; {collection of labels}
MCBFlags : word; {multi checkbox flags}
SelRange : byte; {multi checkbox SelRange}
States : PString;); {multi checkbox States}
ListB:
(Columns : word;
ScrollBar : PString;); {variable name of scrollbar}
Memo: (TextFieldName : PString; {the second DataRec fieldname required by TMemo}
BufSize : word; {size of buffer}
VScroll, HScroll : PString;); {variable name of scrollbars}
end;
PScriptRec = ^ScriptRec;
BitFunction = function(W : word): string;
var
P, Dialog : PScriptRec;
ScriptColl : PCollection;
Present : array[Dlg..ScrollB] of boolean; {which types are present}
const
ValidatorPresent : boolean = False;
procedure ChkIOerror(S : string);
{main script reading procedure}
procedure ReadScriptFile(FName : string);
{given a byte, word, longint, return the string hex equivalent}
function Hex2(B : Byte) : String;
function Hex4(W : word) : string;
function Hex8(L : LongInt) : string;
{compare two strings without regard to case}
function SameString(const S1, S2 : String) : Boolean;
{if the filename has no extension, add the default extension}
function DefaultExt(const FName, DefExt : string) : string;
{functions use by OptionStr}
function GetWinFlagWords(W : word): string;
function GetEventWords(W : word): string;
function GetOptionWords(W : word): string;
{given default and actual options (or eventmask), come up with a source
code phrase something like 'or ofFramed and not ofSelectable'. Func is
a function appropriate to the type of bits being looked at.
It's known that Actual and Default are not equal on entry}
function OptionStr(Actual, Default : word; Func : BitFunction): string;
Implementation
Const
VersionID = 'SCRIPT1';
Tab = #9;
type
PairType = array[0..1] of Char; {reads two characters at once}
var
Spair : PairType;
LCh : Char absolute SPair; {same address as SPair so LCh = Spair[0]}
Chi, LineNo : integer;
St : String;
Inf : Text;
L : LongInt;
function GetWinFlagWords(W : word): string;
const
FlagArray : array[0..3] of String[7] =
('wfMove', 'wfGrow', 'wfClose', 'wfZoom');
var
S : string;
I : integer;
begin
S := '';
for I := 0 to 3 do
begin
if (W and 1 = 1) then
S := S+FlagArray[I] + ' or ';
W := W shr 1;
end;
if Length(S) > 4 then Dec(S[0], 4); {remove last ' or '}
GetWinFlagWords := S;
end;
function GetEventWords(W : word): string;
const
FlagArray : array[0..15] of String[11] =
('evMouseDown', 'evMouseUp', 'evMouseMove', 'evMouseAuto',
'evKeyDown', '$20', '$40', '$80', 'evCommand', 'evBroadcast',
'$400', '$800', '$1000', '$2000', '$4000', '$8000');
var
S : string;
I : integer;
begin
S := '';
for I := 0 to 15 do
begin
if (W and 1 = 1) and (FlagArray[I] <> '') then
S := S+FlagArray[I] + ' or ';
W := W shr 1;
end;
if Length(S) > 4 then Dec(S[0], 4); {remove last ' or '}
GetEventWords := S;
end;
function GetOptionWords(W : word): string;
const
FlagArray : array[0..15] of String[13] =
('ofSelectable', 'ofTopSelect', 'ofFirstClick', 'ofFramed',
'ofPreProcess', 'ofPostProcess', 'ofBuffered', 'ofTileable',
'ofCenterX', 'ofCenterY', 'ofValidate', '$800', 'ofVersion20',
'$2000', '$4000', 'ofShoehorn');
var
S : string;
I : integer;
begin
S := '';
for I := 0 to 15 do
begin
if (W and 1 = 1) and (FlagArray[I] <> '') then
S := S+FlagArray[I] + ' or ';
W := W shr 1;
end;
if Length(S) > 4 then Dec(S[0], 4); {remove last ' or '}
GetOptionWords := S;
end;
function BitCount(W : word): integer; {number of set bits in W}
var
I, Count : integer;
begin
Count := 0;
for I := 0 to 15 do
begin
if W and 1 = 1 then
Inc(Count);
W := W shr 1;
end;
BitCount := Count;
end;
function OptionStr(Actual, Default : word; Func : BitFunction): string;
{given default and actual options (or eventmask), come up with a source
code phrase something like 'or ofFramed and not ofSelectable'. Func is
a function appropriate to the type of bits being looked at.
It's known that Actual and Default are not equal on entry}
var
S : string;
NOTs, ORs, Diff : word;
begin
Diff := Actual xor Default; {the bits that are different}
if BitCount(Diff) > 4 then
begin {this is too complex--output hex number}
OptionStr := '$'+Hex4(Actual)+';';
Exit;
end;
NOTs := Diff and Default; {the bits not in default}
ORs := Diff and Actual; {the extra bits in actual}
S := '';
if NOTs <> 0 then
if BitCount(NOT